package ext.tianma.part.util;

/**
 * 
 * User: Administrator
 * Date: 2008-9-1
 * Time: 19:30:05
 * To change this template use File | Settings | File Templates.
 */
import java.io.PrintStream;
import java.io.Serializable;
import java.rmi.RemoteException;
import java.sql.Timestamp;
import java.util.*;

import wt.csm.navigation.ClassificationNode;
import wt.fc.Persistable;
import wt.fc.PersistenceHelper;
import wt.fc.QueryResult;
import wt.fc.WTObject;
import wt.iba.definition.AbstractAttributeDefinition;
import wt.iba.definition.DefinitionLoader;
import wt.iba.definition.IBADefinitionException;
import wt.iba.definition.litedefinition.*;
import wt.iba.definition.service.IBADefinitionHelper;
import wt.iba.definition.service.IBADefinitionService;
import wt.iba.value.*;
import wt.iba.value.litevalue.AbstractValueView;
import wt.iba.value.litevalue.BooleanValueDefaultView;
import wt.iba.value.litevalue.FloatValueDefaultView;
import wt.iba.value.litevalue.RatioValueDefaultView;
import wt.iba.value.litevalue.ReferenceValueDefaultView;
import wt.iba.value.litevalue.StringValueDefaultView;
import wt.iba.value.litevalue.TimestampValueDefaultView;
import wt.iba.value.litevalue.URLValueDefaultView;
import wt.iba.value.litevalue.UnitValueDefaultView;
import wt.iba.value.service.*;
import wt.part.WTPart;
import wt.query.QuerySpec;
import wt.query.SearchCondition;
import wt.session.SessionHelper;
import wt.session.SessionManager;
import wt.util.WTException;
import wt.util.WTPropertyVetoException;

public class IBAUtil implements Serializable, wt.method.RemoteAccess {

	Hashtable ibaContainer;
	private static Locale LOCALE = Locale.CHINA;

	private static boolean VERBOSE = false;

	private IBAUtil() {
		ibaContainer = new Hashtable();
	}

	public IBAUtil(IBAHolder ibaholder) {
		initializeIBAPart(ibaholder);
	}

	public String toString() {
		StringBuffer stringbuffer = new StringBuffer();
		Enumeration enumeration = ibaContainer.keys();
		try {
			while (enumeration.hasMoreElements()) {
				String s = (String) enumeration.nextElement();
				AbstractValueView abstractvalueview = (AbstractValueView) ((Object[]) ibaContainer.get(s))[1];
				stringbuffer.append(s + " - " + IBAValueUtility.getLocalizedIBAValueDisplayString(abstractvalueview,
						SessionHelper.manager.getLocale()));
				stringbuffer.append('\n');
			}
		} catch (Exception exception) {
			exception.printStackTrace();
		}
		return stringbuffer.toString();
	}

	public String getIBAValue(String s) {
		try {
			return getIBAValue(s, SessionHelper.manager.getLocale());
		} catch (WTException wte) {
			wte.printStackTrace();
		}
		return "";
	}

	public String getIBAValue(String s, Locale locale) {
		try {
			Object[] obj = (Object[]) ibaContainer.get(s);
			if (obj == null)
				return "";
			AbstractValueView abstractvalueview = (AbstractValueView) obj[1];
			return IBAValueUtility.getLocalizedIBAValueDisplayString(abstractvalueview, locale);
		} catch (WTException wte) {
			wte.printStackTrace();
		}
		return "";
	}

	private void initializeIBAPart(IBAHolder ibaholder) {
		ibaContainer = new Hashtable();
		try {
			ibaholder = IBAValueHelper.service.refreshAttributeContainer(ibaholder, null,
					SessionHelper.manager.getLocale(), null);
			DefaultAttributeContainer defaultattributecontainer = (DefaultAttributeContainer) ibaholder
					.getAttributeContainer();
			if (defaultattributecontainer != null) {
				AttributeDefDefaultView aattributedefdefaultview[] = defaultattributecontainer
						.getAttributeDefinitions();
				for (int i = 0; i < aattributedefdefaultview.length; i++) {
					AbstractValueView aabstractvalueview[] = defaultattributecontainer
							.getAttributeValues(aattributedefdefaultview[i]);
					if (aabstractvalueview != null) {
						Object aobj[] = new Object[2];
						aobj[0] = aattributedefdefaultview[i];
						aobj[1] = aabstractvalueview[0];
						ibaContainer.put(aattributedefdefaultview[i].getName(), ((Object) (aobj)));
					}
				}

			}
		} catch (Exception exception) {
			exception.printStackTrace();
		}
	}

	public IBAHolder updateIBAPart(IBAHolder ibaholder) throws Exception {
		ibaholder = IBAValueHelper.service.refreshAttributeContainer(ibaholder, null, SessionHelper.manager.getLocale(),
				null);
		DefaultAttributeContainer defaultAttributeContainer = (DefaultAttributeContainer) (IBAValueHelper.service
				.refreshAttributeContainerWithoutConstraints(ibaholder)).getAttributeContainer();
		for (Enumeration enumeration = ibaContainer.elements(); enumeration.hasMoreElements();) {
			try {
				Object aobj[] = (Object[]) enumeration.nextElement();
				AbstractValueView abstractvalueview = (AbstractValueView) aobj[1];
				AttributeDefDefaultView attributedefdefaultview = (AttributeDefDefaultView) aobj[0];
				if (abstractvalueview.getState() == 1) {
					defaultAttributeContainer.deleteAttributeValues(attributedefdefaultview);
					abstractvalueview.setState(3);
					defaultAttributeContainer.addAttributeValue(abstractvalueview);
				}
			} catch (Exception exception) {
				exception.printStackTrace();
			}
		}
		defaultAttributeContainer.setConstraintParameter(new String("CSM"));
		ibaholder.setAttributeContainer(defaultAttributeContainer);
		LoadValue.applySoftAttributes(ibaholder);// add by bjia 20090817
		return ibaholder;
	}

	public void setIBAValue(String s, String s1) throws WTPropertyVetoException {
		AbstractValueView abstractvalueview = null;
		AttributeDefDefaultView attributedefdefaultview = null;
		Object aobj[] = (Object[]) ibaContainer.get(s);
		if (aobj != null) {
			abstractvalueview = (AbstractValueView) aobj[1];
			attributedefdefaultview = (AttributeDefDefaultView) aobj[0];
		}
		if (abstractvalueview == null)
			attributedefdefaultview = getAttributeDefinition(s);
		if (attributedefdefaultview == null) {
			System.out.println("definition is null ...");
			return;
		}
		abstractvalueview = internalCreateValue(attributedefdefaultview, s1);
		if (abstractvalueview == null) {
			System.out.println("after creation, iba value is null ..");
			return;
		} else {
			abstractvalueview.setState(1);
			Object aobj1[] = new Object[2];
			aobj1[0] = attributedefdefaultview;
			aobj1[1] = abstractvalueview;
			ibaContainer.put(attributedefdefaultview.getName(), ((Object) (aobj1)));
			return;
		}
	}

	private AttributeDefDefaultView getAttributeDefinition(String s) {
		AttributeDefDefaultView attributedefdefaultview = null;
		try {
			attributedefdefaultview = IBADefinitionHelper.service.getAttributeDefDefaultViewByPath(s);
			if (attributedefdefaultview == null) {
				AbstractAttributeDefinizerView abstractattributedefinizerview = DefinitionLoader
						.getAttributeDefinition(s);
				if (abstractattributedefinizerview != null)
					attributedefdefaultview = IBADefinitionHelper.service
							.getAttributeDefDefaultView((AttributeDefNodeView) abstractattributedefinizerview);
			}
		} catch (Exception exception) {
			exception.printStackTrace();
		}
		return attributedefdefaultview;
	}

	private AbstractValueView internalCreateValue(AbstractAttributeDefinizerView abstractattributedefinizerview,
			String s) {
		AbstractValueView abstractvalueview = null;
		if (abstractattributedefinizerview instanceof FloatDefView)
			abstractvalueview = LoadValue.newFloatValue(abstractattributedefinizerview, s, null);
		else if (abstractattributedefinizerview instanceof StringDefView)
			abstractvalueview = LoadValue.newStringValue(abstractattributedefinizerview, s);
		else if (abstractattributedefinizerview instanceof IntegerDefView)
			abstractvalueview = LoadValue.newIntegerValue(abstractattributedefinizerview, s);
		else if (abstractattributedefinizerview instanceof RatioDefView)
			abstractvalueview = LoadValue.newRatioValue(abstractattributedefinizerview, s, null);
		else if (abstractattributedefinizerview instanceof TimestampDefView)
			abstractvalueview = LoadValue.newTimestampValue(abstractattributedefinizerview, s);
		else if (abstractattributedefinizerview instanceof BooleanDefView)
			abstractvalueview = LoadValue.newBooleanValue(abstractattributedefinizerview, s);
		else if (abstractattributedefinizerview instanceof URLDefView)
			abstractvalueview = LoadValue.newURLValue(abstractattributedefinizerview, s, null);
		else if (abstractattributedefinizerview instanceof ReferenceDefView)
			abstractvalueview = LoadValue.newReferenceValue(abstractattributedefinizerview, "ClassificationNode", s);
		else if (abstractattributedefinizerview instanceof UnitDefView)
			abstractvalueview = LoadValue.newUnitValue(abstractattributedefinizerview, s, null);
		return abstractvalueview;
	}

	public static boolean isClassified(WTPart part) {

		boolean isClassified = false;
		IBAHolder ibaholder = (IBAHolder) part;
		if (ibaholder != null) {
			try {
				ibaholder = IBAValueHelper.service.refreshAttributeContainer(ibaholder, null, LOCALE, null);
				DefaultAttributeContainer defaultattributecontainer = (DefaultAttributeContainer) ibaholder
						.getAttributeContainer();

				if (defaultattributecontainer != null) {
					if (VERBOSE)
						System.out.println(" -- Get the values from the container");
					AbstractValueView aabstractvalueview[] = null;
					AbstractValueView avv = null;

					aabstractvalueview = defaultattributecontainer.getAttributeValues();
					System.out.println("aabstractvalueview.length--->" + aabstractvalueview.length);
					for (int j = 0; j < aabstractvalueview.length; j++) {
						System.out.println(aabstractvalueview[j]);

						if (aabstractvalueview[j] instanceof ReferenceValueDefaultView) {
							ReferenceValueDefaultView referenceValueDefaultView = (ReferenceValueDefaultView) aabstractvalueview[j];
							ReferenceDefView referenceDefView = referenceValueDefaultView.getReferenceDefinition();
							String ReferencedClassname = referenceDefView.getReferencedClassname();
							if (ReferencedClassname.equalsIgnoreCase("wt.csm.navigation.ClassificationNode")) {
								isClassified = true;
								break;
							} else {
								continue;
							}
						} else {

							continue;
						}
					}
				}
			} catch (RemoteException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (WTException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

		return isClassified;

	}

	public Hashtable getPartAttribute(WTPart part) throws RemoteException, WTException {

		Hashtable hashtable = new Hashtable();

		IBAHolder ibaholder = (IBAHolder) part;

		ibaholder = IBAValueHelper.service.refreshAttributeContainer(ibaholder, null, LOCALE, null);
		DefaultAttributeContainer defaultattributecontainer = (DefaultAttributeContainer) ibaholder
				.getAttributeContainer();

		if (defaultattributecontainer != null) {
			if (VERBOSE)
				System.out.println(" -- Get the values from the container");
			AbstractValueView aabstractvalueview[] = null;
			AbstractValueView avv = null;

			aabstractvalueview = defaultattributecontainer.getAttributeValues();
			for (int j = 0; j < aabstractvalueview.length; j++) {
				String thisIBAName = aabstractvalueview[j].getDefinition().getDisplayName();
				String thisIBAValue = IBAValueUtility.getLocalizedIBAValueDisplayString(aabstractvalueview[j], LOCALE);
				String thisIBAClass = (aabstractvalueview[j].getDefinition()).getAttributeDefinitionClassName();
				if (VERBOSE)
					System.out.println(" ** -- IBA " + thisIBAName + " - " + thisIBAValue + " - " + thisIBAClass);
				hashtable.put(thisIBAName, thisIBAValue);

			}
		}

		return hashtable;

	}

	// �ж�ĳ��iba�����Ƿ�����ķ���ʹ��
	public static boolean isInUseByClassification(AbstractAttributeDefinition abstractattributedefinition)
			throws WTException, IBADefinitionException {
		QueryResult queryresult = new QueryResult();
		QuerySpec queryspec = new QuerySpec(abstractattributedefinition.getValueClassname());
		String s = "definitionReference";
		try {
			queryspec.appendSearchCondition(
					new SearchCondition(Class.forName(abstractattributedefinition.getValueClassname()),
							(new StringBuilder()).append(s).append(".").append("key").toString(), "=",
							abstractattributedefinition.getPersistInfo().getObjectIdentifier()));
		} catch (ClassNotFoundException classnotfoundexception) {
			Object aobj[] = { abstractattributedefinition.getValueClassname(), " " };
			throw new IBADefinitionException("wt.iba.definition.service.serviceResource", "10", aobj);
		}
		queryresult = PersistenceHelper.manager.find(queryspec);

		Vector users = new Vector();

		while (queryresult.hasMoreElements()) {

			AbstractContextualValue abstractContextualValue = (AbstractContextualValue) queryresult.nextElement();
			wt.fc.ReferenceFactory factory = new wt.fc.ReferenceFactory();

			Persistable obj = factory.getReference(abstractContextualValue.getIBAHolderReference().toString())
					.getObject();

			if (obj instanceof wt.csm.navigation.ClassificationNode) {

				ClassificationNode node = (ClassificationNode) obj;
				if (VERBOSE)
					System.out.println(node.getName());
				users.add(node);
			}

		}

		return users.size() > 0;
	}

	public static Vector getInUseByClassification(AbstractAttributeDefinition abstractattributedefinition)
			throws WTException, IBADefinitionException {

		Vector users = new Vector();
		QueryResult queryresult = new QueryResult();
		QuerySpec queryspec = new QuerySpec(abstractattributedefinition.getValueClassname());
		String s = "definitionReference";
		try {
			queryspec.appendSearchCondition(
					new SearchCondition(Class.forName(abstractattributedefinition.getValueClassname()),
							(new StringBuilder()).append(s).append(".").append("key").toString(), "=",
							abstractattributedefinition.getPersistInfo().getObjectIdentifier()));
		} catch (ClassNotFoundException classnotfoundexception) {
			Object aobj[] = { abstractattributedefinition.getValueClassname(), " " };
			throw new IBADefinitionException("wt.iba.definition.service.serviceResource", "10", aobj);
		}
		queryresult = PersistenceHelper.manager.find(queryspec);

		while (queryresult.hasMoreElements()) {

			AbstractContextualValue abstractContextualValue = (AbstractContextualValue) queryresult.nextElement();
			wt.fc.ReferenceFactory factory = new wt.fc.ReferenceFactory();

			Persistable obj = factory.getReference(abstractContextualValue.getIBAHolderReference().toString())
					.getObject();

			if (obj instanceof wt.csm.navigation.ClassificationNode) {

				ClassificationNode node = (ClassificationNode) obj;
				System.out.println(node.getName());
				users.add(node);
			}

		}

		return users;
	}

	/**
	 * �ж϶����Ƿ�ӵ��ĳһ��Ƶ�����
	 * 
	 */
	public static Boolean hasAttribute(IBAHolder ibaholder, String name) {

		boolean need = false;

		wt.iba.value.AttributeContainer attributecontainer = null;

		attributecontainer = ibaholder.getAttributeContainer();
		if (attributecontainer == null)
			try {
				ibaholder = IBAValueHelper.service.refreshAttributeContainer(ibaholder, null, null, null);
				attributecontainer = ibaholder.getAttributeContainer();
			} catch (RemoteException remoteexception) {
				remoteexception.printStackTrace();
			} catch (WTException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		DefaultAttributeContainer defaultattributecontainer = (DefaultAttributeContainer) attributecontainer;
		AttributeDefDefaultView aattributedefdefaultview[] = defaultattributecontainer.getAttributeDefinitions();
		System.out.println("aattributedefdefaultview.length--->" + aattributedefdefaultview.length);
		for (int k = 0; k < aattributedefdefaultview.length; k++) {
			AttributeDefDefaultView attributedefdefaultview = aattributedefdefaultview[k];
			String attributeName = attributedefdefaultview.getDisplayName();

			if (VERBOSE)
				System.out.println(attributeName);
			if (attributeName.equalsIgnoreCase(name)) {

				need = true;
				break;
			}

		}

		return need;

	}

	// ��ȡ�����ȷ����IBA������
	public static Vector getAttribute(IBAHolder ibaholder) throws WTException {
		Vector<String> attr = new Vector<String>();
		wt.iba.value.AttributeContainer attributecontainer = null;

		attributecontainer = ibaholder.getAttributeContainer();
		// System.out.println(attributecontainer);
		if (attributecontainer == null)
			try {
				ibaholder = IBAValueHelper.service.refreshAttributeContainer(ibaholder, null, null, null);
				attributecontainer = ibaholder.getAttributeContainer();
			} catch (RemoteException remoteexception) {
				remoteexception.printStackTrace();
			}
		DefaultAttributeContainer defaultattributecontainer = (DefaultAttributeContainer) attributecontainer;
		AttributeDefDefaultView aattributedefdefaultview[] = defaultattributecontainer.getAttributeDefinitions();
		// System.out.println("aattributedefdefaultview[]"+aattributedefdefaultview);
		System.out.println("length" + aattributedefdefaultview.length);
		for (int k = 0; k < aattributedefdefaultview.length; k++) {
			AttributeDefDefaultView attributedefdefaultview = aattributedefdefaultview[k];
			String attribute = attributedefdefaultview.getDisplayName();
			attr.add(attribute);

		}
		System.out.println(attr);
		return attr;
	}

	public static void setIBATimestampValue(WTObject obj, String ibaName, Timestamp newValue) throws WTException {
		String ibaClass = "wt.iba.definition.TimestampDefinition";
		try {
			if (obj instanceof IBAHolder) {
				IBAHolder ibaHolder = (IBAHolder) obj;
				DefaultAttributeContainer defaultattributecontainer = getContainer(ibaHolder);
				if (defaultattributecontainer == null) {
					defaultattributecontainer = new DefaultAttributeContainer();
					ibaHolder.setAttributeContainer(defaultattributecontainer);
				}
				TimestampValueDefaultView abstractvaluedefaultview = (TimestampValueDefaultView) getIBAValueView(
						defaultattributecontainer, ibaName, ibaClass);
				if (abstractvaluedefaultview != null) {
					abstractvaluedefaultview.setValue(newValue);

					defaultattributecontainer.updateAttributeValue(abstractvaluedefaultview);
				} else {
					AttributeDefDefaultView attributedefdefaultview = getAttributeDefinition(ibaName, false);
					TimestampValueDefaultView abstractvaluedefaultview1 = new TimestampValueDefaultView(
							(TimestampDefView) attributedefdefaultview, newValue);
					defaultattributecontainer.addAttributeValue(abstractvaluedefaultview1);
				}
				ibaHolder.setAttributeContainer(defaultattributecontainer);
				StandardIBAValueService.theIBAValueDBService.updateAttributeContainer(ibaHolder, null, null, null);
				ibaHolder = IBAValueHelper.service.refreshAttributeContainer(ibaHolder, "CSM", null, null);
			}
		} catch (Exception exception) {
			exception.printStackTrace();
		}
	}

	public static AttributeDefDefaultView getAttributeDefinition(String s, boolean flag) {
		AttributeDefDefaultView attributedefdefaultview = null;
		try {
			attributedefdefaultview = IBADefinitionHelper.service.getAttributeDefDefaultViewByPath(s);
			if (attributedefdefaultview == null) {
				AbstractAttributeDefinizerView abstractattributedefinizerview = DefinitionLoader
						.getAttributeDefinition(s);
				if (abstractattributedefinizerview != null)
					attributedefdefaultview = IBADefinitionHelper.service
							.getAttributeDefDefaultView((AttributeDefNodeView) abstractattributedefinizerview);
			}
		} catch (Exception exception) {
			exception.printStackTrace();
		}
		return attributedefdefaultview;
	}

	public static DefaultAttributeContainer getContainer(IBAHolder ibaHolder) throws WTException, RemoteException {
		ibaHolder = IBAValueHelper.service.refreshAttributeContainerWithoutConstraints(ibaHolder);
		DefaultAttributeContainer defaultattributecontainer = (DefaultAttributeContainer) ibaHolder
				.getAttributeContainer();
		return defaultattributecontainer;
	}

	public static AbstractValueView getIBAValueView(DefaultAttributeContainer dac, String ibaName, String ibaClass)
			throws WTException {
		AbstractValueView aabstractvalueview[] = null;
		AbstractValueView avv = null;
		aabstractvalueview = dac.getAttributeValues();
		for (int j = 0; j < aabstractvalueview.length; j++) {
			String thisIBAName = aabstractvalueview[j].getDefinition().getName();
			String thisIBAValue = IBAValueUtility.getLocalizedIBAValueDisplayString(aabstractvalueview[j],
					Locale.CHINA);
			String thisIBAClass = (aabstractvalueview[j].getDefinition()).getAttributeDefinitionClassName();
			if (thisIBAName.equals(ibaName) && thisIBAClass.equals(ibaClass)) {
				avv = aabstractvalueview[j];
				break;
			}
		}
		return avv;
	}
	
	/**
	 * luojh   设置属性多值或分类属性  配合使用updateIBAHolderForMultiValueOrClassificationValue方法进行更新
	 * @param s
	 * @param s1
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	public void setIBAValueForMultiValueOrClassificationValue(String s, String s1) throws Exception {
		AbstractValueView abstractvalueview = null;
		AttributeDefDefaultView attributedefdefaultview = null;
		Object aobj[] = (Object[]) ibaContainer.get(s);
		if (aobj != null) {
			attributedefdefaultview = (AttributeDefDefaultView) aobj[0];
		}
		if (attributedefdefaultview == null)
			attributedefdefaultview = getAttributeDefinition(s);
		if (attributedefdefaultview == null) {
			System.out.println("definition is null ...");
			return;
		}
		abstractvalueview = internalCreateValue(attributedefdefaultview, s1);
		if (abstractvalueview == null) {
			System.out.println("after creation, iba value is null ..");
			throw new WTException("转换值出现异常,属性:" + s + "\t值:" + s1);
		} else {
			abstractvalueview.setState(AbstractValueView.NEW_STATE);
			abstractvalueview = updateAbstractView(abstractvalueview);
			Object aobj1[] = null;
			if (ibaContainer.containsKey(attributedefdefaultview.getName())) {
				Object aobj2[] = (Object[]) ibaContainer.get(attributedefdefaultview.getName());
				aobj1 = new Object[aobj2.length + 1];
				aobj1[0] = aobj2[0];
				int a=1;
				for (; a < aobj2.length; a++) {
					AbstractValueView abstractvalue = (AbstractValueView) aobj2[a];
					if (abstractvalue.getState() == 0)
						abstractvalue.setState(AbstractValueView.DELETED_STATE);
					aobj1[a] = abstractvalue;
					// else
					// {
					// aobj1[a]=abstractvalue;
					// }
				}
				aobj1[a] = abstractvalueview;
//				System.out.println("=luojh==========>"+attributedefdefaultview.getName()+"\t"+(aobj1.length-1));
			} else {
				aobj1 = new Object[2];
				aobj1[0] = attributedefdefaultview;
				aobj1[1] = abstractvalueview;
			}
			ibaContainer.put(attributedefdefaultview.getName(), ((aobj1)));
		}
	}
	
	public static AbstractValueView updateAbstractView(AbstractValueView abstractvalueview) throws WTPropertyVetoException {
		if (abstractvalueview instanceof URLValueDefaultView) {
			String display = abstractvalueview.getDefinition().getDisplayName();
			((URLValueDefaultView) abstractvalueview).setDescription(display);
		}
		return abstractvalueview;
	}
	
	/**
	 * luojh 更新属性多值或分类属性  配合使用setIBAValueForMultiValueOrClassificationValue方法进行设置属性
	 * @param ibaholder
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("rawtypes")
	public IBAHolder updateIBAHolderForMultiValueOrClassificationValue(IBAHolder ibaholder) throws Exception {
		ibaholder = IBAValueHelper.service.refreshAttributeContainer(ibaholder, null, Locale.CHINA, null);
		DefaultAttributeContainer defaultattributecontainer = (DefaultAttributeContainer) ibaholder.getAttributeContainer();
		String ibaName = "";
//		Debug.P("=============defaultattributecontainer=start==>"+defaultattributecontainer);
		for (Enumeration enumeration = ibaContainer.elements(); enumeration.hasMoreElements();)
			try {
				Object aobj[] = (Object[]) enumeration.nextElement();
				AttributeDefDefaultView attributedefdefaultview = (AttributeDefDefaultView) aobj[0];
				AbstractValueView[] avs = defaultattributecontainer.getAttributeValues(attributedefdefaultview);
				ibaName = attributedefdefaultview.getDisplayName()+"("+ attributedefdefaultview.getName()+")";
				int b=0;
				for (int a = 1; a < aobj.length; a++) {
					AbstractValueView abstractvalue = (AbstractValueView) aobj[a];
//					Debug.P("================>"+ibaName+a+"/"+(aobj.length-1)+"\tstate:"+abstractvalue.getState()+"/value:"+abstractvalue.getLocalizedDisplayString()+"/b:"+b+"/"+avs.length);
					if (abstractvalue != null && abstractvalue.getState() == AbstractValueView.NEW_STATE){
						if(b<avs.length)
						{
							AbstractValueView avv = avs[b++];
							if (avv instanceof StringValueDefaultView)
								((StringValueDefaultView) avv).setValue(((StringValueDefaultView) abstractvalue).getValue());
							if (avv instanceof BooleanValueDefaultView)
								((BooleanValueDefaultView) avv).setValue(((BooleanValueDefaultView) abstractvalue).isValue());
							if (avv instanceof FloatValueDefaultView)
								((FloatValueDefaultView) avv).setValue(((FloatValueDefaultView) abstractvalue).getValue());
							if (avv instanceof UnitValueDefaultView)
								((UnitValueDefaultView) avv).setValue(((UnitValueDefaultView) abstractvalue).getValue());
							if (avv instanceof URLValueDefaultView)
								((URLValueDefaultView) avv).setValue(((URLValueDefaultView) abstractvalue).getValue());
							if (avv instanceof RatioValueDefaultView)
								((RatioValueDefaultView) avv).setValue(((RatioValueDefaultView) abstractvalue).getValue());
							if (avv instanceof TimestampValueDefaultView)
								((TimestampValueDefaultView) avv).setValue(((TimestampValueDefaultView) abstractvalue).getValue());
							defaultattributecontainer.updateAttributeValue(avv);
						}
						else 
							defaultattributecontainer.addAttributeValue(abstractvalue);
					}
				}
				if(b>0)
				{
					for(;b<avs.length;b++)
					{
//						Debug.P("================>"+"/b:"+b+"/"+avs.length+"/State:"+avs[b].getState());
							defaultattributecontainer.deleteAttributeValue(avs[b]);
					}
				}
			} catch (Exception exception) {
				exception.printStackTrace();
				throw new Exception("属性:" + ibaName + exception.getLocalizedMessage());
			}
//			Debug.P("=============defaultattributecontainer=end==>"+defaultattributecontainer);
		ibaholder.setAttributeContainer(defaultattributecontainer);
		return ibaholder;
	}
}
